<!DOCTYPE html>
<!-- Based on https://material-components-web.appspot.com/card.html -->
<html class="mdc-typography">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <title>Open-Source Licenses</title>
        <link
                rel="stylesheet"
                href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">
        <style>
            body {
                background-color: #f2f2f2;
            }
            main {
                padding: 24px;
            }
            #demo-wrapper {
                margin: 24px;
                display: flex;
                flex-flow: row wrap;
                align-content: center;
                justify-content: center;
            }
            #demo-wrapper .demo-card {
                margin: 24px;
            }
            .demo-card {
                margin-bottom: 48px;
                background: white;
            }
            .license-text {
                font-family: monospace;
                white-space: pre;
            }
        </style>
        <script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script>
        <script id="library-template" type="text/x-handlebars-template">
            <div class="mdc-card demo-card">
                <section class="mdc-card__primary">
                    <h1 class="mdc-card__title mdc-card__title--large">{{name}}</h1>
                    <h2 class="mdc-card__subtitle">{{copyright}}</h2>
                </section>
                <section class="mdc-card__supporting-text license-text">{{license}}</section>
            </div>
        </script>
        <script type="application/javascript">
            const LICENSES = {
                "apache2": `
                    Licensed under the Apache License, Version 2.0 (the "License");
                    you may not use this file except in compliance with the License.
                    You may obtain a copy of the License at

                        https://www.apache.org/licenses/LICENSE-2.0

                    Unless required by applicable law or agreed to in writing, software
                    distributed under the License is distributed on an "AS IS" BASIS,
                    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                    See the License for the specific language governing permissions and
                    limitations under the License.`,
                  "mit": `
                    Permission is hereby granted, free of charge, to any person obtaining a copy
                    of this software and associated documentation files (the "Software"), to deal
                    in the Software without restriction, including without limitation the rights
                    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                    copies of the Software, and to permit persons to whom the Software is
                    furnished to do so, subject to the following conditions:

                    The above copyright notice and this permission notice shall be included in all
                    copies or substantial portions of the Software.

                    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
                    SOFTWARE.`
            };

            var LIBRARIES = [
              {
                  "name": "AutoDispose",
                  "url": "https://github.com/uber/AutoDispose",
                  "copyright": "Copyright (C) 2017 Uber Technologies",
                  "license": "apache2"
              },
              {
                  "name": "Dagger",
                  "url": "https://google.github.io/dagger",
                  "copyright": "Copyright 2012 The Dagger Authors",
                  "license": "apache2"
              },
              {
                  "name": "Google API Client",
                  "url": "https://github.com/google/google-api-java-client",
                  "license": "apache2"
              },
              {
                  "name": "Java Native Access",
                  "url": "https://github.com/java-native-access/jna",
                  "license": "apache2"
              },
              {
                  "name": "Koptional",
                  "url": "https://github.com/gojuno/koptional",
                  "copyright": "Copyright 2017 Juno, Inc.",
                  "license": "apache2"
              },
              {
                  "name": "Kotlin",
                  "url": "https://kotlinlang.org",
                  "copyright": "Copyright 2010-2017 JetBrains s.r.o.",
                  "license": "apache2"
              },
              {
                  "name": "LibRetro",
                  "url": "https://www.libretro.com/index.php/api",
                  "copyright": "Copyright (C) 2010-2017 The RetroArch team",
                  "license": "mit"
              },
              {
                  "name": "OkHttp",
                  "url": "https://github.com/square/okhttp",
                  "license": "apache2",
              },
              {
                  "name": "Picasso",
                  "url": "https://github.com/square/picasso",
                  "copyright": "Copyright 2013 Square, Inc.",
                  "license": "apache2"
              },
              {
                  "name": "Retrofit",
                  "url": "https://github.com/square/retrofit",
                  "copyright": "Copyright 2013 Square, Inc.",
                  "license": "apache2"
              },
              {
                  "name": "RxAndroid",
                  "url": "https://github.com/ReactiveX/RxAndroid",
                  "copyright": "Copyright 2015 The RxAndroid authors",
                  "license": "apache2"
              },
              {
                  "name": "RxJava",
                  "url": "https://github.com/ReactiveX/RxJava",
                  "copyright": "Copyright (c) 2016-present, RxJava Contributors.",
                  "license": "apache2"
              },
              {
                  "name": "RxPermissions",
                  "url": "https://github.com/tbruyelle/RxPermissions",
                  "copyright": "Copyright (C) 2015 Thomas Bruyelle",
                  "license": "apache2"
              },
              {
                  "name": "RxPreferences",
                  "url": "https://github.com/f2prateek/rx-preferences",
                  "copyright": "Copyright (C) 2015 Thomas Bruyelle",
                  "license": "apache2"
              },
              {
                  "name": "RxRelay",
                  "url": "https://github.com/JakeWharton/RxRelay",
                  "copyright": "Copyright 2014 Netflix, Inc. Copyright 2015 Jake Wharton",
                  "license": "apache2"
              },
              {
                  "name": "Timber",
                  "url": "https://github.com/JakeWharton/timber",
                  "copyright": "Copyright 2013 Jake Wharton",
                  "license": "apache2"
              }
            ];

            // https://github.com/thejameskyle/min-indent/blob/master/index.js
            function minIndent(str) {
              const match = str.match(/^[ \t]*(?=\S)/gm);
              if (!match) {
                return 0;
              }
              return Math.min.apply(Math, match.map(x => x.length));
            }

            // https://github.com/sindresorhus/strip-indent/blob/master/index.js
            function stripIndent(str) {
              const indent = minIndent(str);
              if (indent === 0) {
                return str;
              }
              const re = new RegExp(`^[ \\t]{${indent}}`, 'gm');
              return str.replace(re, '');
            }

            window.onload = function() {
              let librariesDiv = document.getElementById("demo-wrapper");
              LIBRARIES.forEach((library) => {
                  library.license = stripIndent(LICENSES[library.license] || "");
                  let source   = document.getElementById("library-template").innerHTML;
                  let template = Handlebars.compile(source);
                  let div = document.createElement("div");
                  div.innerHTML = template(library);
                  librariesDiv.appendChild(div);
                });
              };
        </script>
    </head>
    <body class="mdc-typography">
        <header class="mdc-toolbar mdc-toolbar--fixed">
            <div class="mdc-toolbar__row">
                <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
                    <span class="mdc-toolbar__title catalog-title">Open-Source Licenses</span>
                </section>
            </div>
        </header>
        <main id="libraries">
            <div class="mdc-toolbar-fixed-adjust"></div>
            <section class="demo-typography--section" id="demo-wrapper">
            </section>
        </main>
    </body>
</html>
